package com.chaosj.memory.handlers;

import com.chaosj.memory.dto.DisorderDto;

import java.util.HashSet;
import java.util.Set;

/**
 * @className: DisorderAZHandler
 * @description:
 * @author: caoyangjie
 * @date: 2021/8/10
 **/
public class DisorderAZHandler extends AbstractToolHandler<DisorderDto> {
    @Override
    public String name() {
        return "disorder";
    }

    @Override
    public void handler(DisorderDto req, StringBuffer outBuffer) {
        StringBuffer newBuffer = new StringBuffer();
        Set<Integer> has = new HashSet<>();
        for ( int i = 0 ; i < req.getLetters(); i ++ ) {
            int nextVal = 0;
            do{
                nextVal = next.nextInt(65+req.getLetters());
            } while ( has.contains(nextVal) || nextVal<65 || nextVal > 65 + req.getLetters() );
            has.add(nextVal);
            outBuffer.append(String.format("  %s  ",(char)nextVal));
            nextVal = nextVal - 64;
            newBuffer.append(String.format("  %s ",nextVal<10?"0"+nextVal:nextVal));
        }
        outBuffer.append("\n");
        outBuffer.append(newBuffer).append("\n");
    }

    @Override
    public DisorderDto cmd2Dto(String[] args) {
        return new DisorderDto(args);
    }
}
